#!/bin/bash

docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana

docker network create --driver bridge --subnet 172.18.0.0/24 --gateway 172.18.0.1 mynet

docker run -d --name node-exporter --restart=always \
  -p 9100:9100 \
  -v "/proc:/host/proc:ro" \
  -v "/sys:/host/sys:ro" \
  -v "/:/rootfs:ro" \
  --net="mynet" \
  prom/node-exporter

netstat -anpt

#http://192.168.202.10:9100/metrics

dockerPath=/opt/docker
mkdir -p $dockerPath
prometheusPath=$dockerPath/prometheus
mkdir -p $prometheusPath
cat >> $prometheusPath/prometheus.yml <<EOF
global:
  scrape_interval:     60s
  evaluation_interval: 60s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus

  - job_name: linux
    static_configs:
      - targets: ['192.168.202.10:9100']
        labels:
          instance: localhost

EOF

docker run  -d --name prometheus --restart=always \
  -p 9090:9090 \
  -v $prometheusPath/prometheus.yml:/etc/prometheus/prometheus.yml  \
  prom/prometheus

#http://192.168.202.10:9090/graph
#http://192.168.202.10:9090/targets

grafanaPath=$dockerPath/grafana
mkdir -p $grafanaPath
chmod 777 -R $grafanaPath

docker run -d --name grafana --restart=always \
  -p 3000:3000 \
  --name=grafana \
  -v $grafanaPath:/var/lib/grafana \
  grafana/grafana

#http://192.168.202.10:3000/
#admin/ning123654
